<?php

function __startsWith($haystack, $needle) {
    $length = strlen($needle);
    return (substr($haystack, 0, $length) === $needle);
}

function __endsWith($haystack, $needle) {
    $length = strlen($needle);
    $start = $length * -1; //negative
    return (substr($haystack, $start) === $needle);
}
error_reporting(1);
function getLatLong($address) {

   //$prepAddr = str_replace(' ','+',$address);
        $geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.urlencode($prepAddr).'&sensor=false');
        $output= json_decode($geocode);
        $latitude = $output->results[0]->geometry->location->lat;
        $longitude = $output->results[0]->geometry->location->lng;
	 return $latitude . ',' . $longitude;
}
?>

<script type="text/javascript">
    var aho;
    var aho2;
    var TrainStations, BusStops,SubWays,NearbyPlaces;
    var glob;
    var output='';
    function getDistanceFromLatLonInKm(lat1,lon1,lat2,lon2) {
        var R = 6371; // Radius of the earth in km
        var dLat = deg2rad(lat2-lat1);  // deg2rad below
        var dLon = deg2rad(lon2-lon1);
        var a =
            Math.sin(dLat/2) * Math.sin(dLat/2) +
            Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
            Math.sin(dLon/2) * Math.sin(dLon/2)
        ;
        var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
        var d = R * c; // Distance in km
        return Math.round(d*100)/100;
    }

    function deg2rad(deg) {
        return deg * (Math.PI/180)
    }
    var nearby;
    var request;

    var counter=1;

    var result;
    var marker;
    var service;
    var map;
    function initialize() {

        var mapOptions = {
            center: new google.maps.LatLng(-34.397, 150.644),
            zoom: 8,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById("map-canvas"),
        mapOptions);


        var geocoder = new google.maps.Geocoder();

        var start ;
        map.setZoom(11);
        var infowin;

<?
if (("LISTING_TYPE" == $data[0]) && (!empty($listing))) {
    ?>
                start='<?= $listing['Listing']['address_1']; ?>';

                geocoder.geocode( { 'address': start}, function(results2, status) {
                    setTimeout('', 100);
                    if (status == google.maps.GeocoderStatus.OK) {
    <?php
    $out = '<div id="listing-rate" style="vertical-align: middle;padding-bottom: 2px;padding-top: 2px;width: 165px">';
    if ((($i_AVGRating * 2) % 2) == 0) {
        $i_MaxEn = $i_AVGRating;
        $i_MaxDis = 5 - $i_MaxEn;
        $b_Half = false;
    } else {
        $i_MaxEn = $i_AVGRating - 0.5;
        $i_MaxDis = 5 - ($i_MaxEn + 1);
        $b_Half = true;
    }
    for ($i = 0; $i < $i_MaxEn; $i++) :
        $out = $out . '<img src="' . SITE_WEBROOT . 'img/stars_enabled.png" width="15"/>';
    endfor;
    if ($b_Half):
        $out = $out . '<img src="' . SITE_WEBROOT . 'img/stars_half.png" width="15"/>';
    endif;
    for ($i = 0; $i < $i_MaxDis; $i++) :
        $out = $out . '<img src="' . SITE_WEBROOT . 'img/stars_disabled.png" width="15"/>';
    endfor;
    $out = $out . '<span style="float: right;">&nbsp;&nbsp;' . $i_TotalReview . ' мнения</span>';
    $out = $out . '<br/>' . $listing['Listing']['address_1'];
    $out = $out . '<div style="clear: both;"></div>';
    $out = $out . '</div>';

    $out = str_replace('"', "'", $out);

    $link = '<a href="' . SITE_WEBROOT . $listing["Listing"]["url_title"] . '-l' . $listing["Listing"]["id"] . '.html">' . htmlspecialchars($listing["Listing"]["title"]) . '</a>';
    $link = str_replace('"', "'", $link);
    ?>

                        infowin = new google.maps.InfoWindow({
                            content:"<div class='wam-googft-info-window'><?= $link ?><br><?= $out ?></div>"
                        });
                        marker = new google.maps.Marker({ map: map});
                        marker.setVisible(false);
                        /*google.maps.event.addListener(marker, 'click', function() {
                                            infowin.open(map,marker);
                                        });*/
                        map.setCenter(results2[0].geometry.location);
                        marker.setPosition(results2[0].geometry.location);
                        marker.setVisible(true);
                       } else {
                        // alert("Geocode was not successful for the following reason: " + status);
                    }
                });
                // setTimeout('', 100);


                //                var marker;
    <?
}

foreach ($listings as $listing) {
    $link = '<a href="' . SITE_WEBROOT . $listing["Listing"]["url_title"] . '-l' . $listing["Listing"]["id"] . '.html">' . htmlspecialchars($listing["Listing"]["title"]) . '</a>';
    $link = str_replace('"', "'", $link);
    $out = '<div id="listing-rate" style="vertical-align: middle;padding-bottom: 2px;padding-top: 2px;width: 165px">';
    if ((($i_AVGRating * 2) % 2) == 0) {
        $i_MaxEn = $i_AVGRating;
        $i_MaxDis = 5 - $i_MaxEn;
        $b_Half = false;
    } else {
        $i_MaxEn = $i_AVGRating - 0.5;
        $i_MaxDis = 5 - ($i_MaxEn + 1);
        $b_Half = true;
    }
    for ($i = 0; $i < $i_MaxEn; $i++) :
        $out = $out . '<img src="' . SITE_WEBROOT . 'img/stars_enabled.png" width="15"/>';
    endfor;
    if ($b_Half):
        $out = $out . '<img src="' . SITE_WEBROOT . 'img/stars_half.png" width="15"/>';
    endif;
    for ($i = 0; $i < $i_MaxDis; $i++) :
        $out = $out . '<img src="' . SITE_WEBROOT . 'img/stars_disabled.png" width="15"/>';
    endfor;
    $out = $out . '<span style="float: right;">&nbsp;&nbsp;' . $i_TotalReview . ' мнения</span>';
    $out = $out . '<br/>' . $listing['Listing']['address_1'];
    $out = $out . '<div style="clear: both;"></div>';
    $out = $out . '</div>';

    $out = str_replace('"', "'", $out);
    ?>


                start='<?= $listing['Listing']['address_1']; ?>';

                geocoder.geocode( { 'address': start}, function(results2, status) {
                    setTimeout('', 100);
                    if (status == google.maps.GeocoderStatus.OK) {

                        marker = new google.maps.Marker({ map: map,
                            position:results2[0].geometry.location
                        });
                        var contentstr="<div class='wam-googft-info-window'><?= $link ?><br><?= $out ?></div>";
                        marker.content=contentstr;
                        marker.setVisible(false);
                        var veh_infowindow = new google.maps.InfoWindow({
                            content:contentstr
                        });

                        google.maps.event.addListener(marker, 'click', function() {
                            veh_infowindow.setContent(this.content);
                            veh_infowindow.open(map,this);
                        });
                        map.setCenter(results2[0].geometry.location);
                        // marker.setPosition(results2[0].geometry.location);
                        marker.setVisible(true);


                    }
                });
<? } ?>
    }
    google.maps.event.addDomListener(window, 'load', initialize);
</script>
<style type="text/css">
    #map-canvas { height: 200px; }
</style>
<?php
/*
echo $form->create('Listings',array('action' => 'search'));
echo $form->input('Listings.search',array('label'=>'Search For'));
echo $form->input('Listings.nearby',array('label'=>'Near'));
echo $form->end('Search');*/
?>

<?
if (($data[0] == "LOCATION_TYPE") || ($data[0] == "CATEGORYLOCATION_TYPE") || ($data[0] == "CATEGORY_TYPE")) {
    ?>
    <div class="listings index">
        <h1><?php
    if ($data[0] == "LOCATION_TYPE") {
        echo htmlspecialchars($data[1]["Location"]["name"]);
    } else if ($data[0] == "CATEGORYLOCATION_TYPE") {
        echo htmlspecialchars($data[1]["Category"]["name"] . ' в ' . $data[2]["Location"]["name"]);
    } else if ($data[0] == "CATEGORY_TYPE") {
        echo htmlspecialchars($data[1]["Category"]["name"]);
    }
    ?></h1>

    <?php if (!empty($locations)): ?>
            <div class="box">
                <div class="box-caption-fixed">City in <?php echo $data[1]['Location']['name']; ?></div>
                <div class="box-content-fixed ">
                    <table border="0" class="categories">
        <?php
        if (!empty($locations)) {
            $i = 1;
            foreach ($locations as $location) {
                if ($i == 1)
                    echo '<tr>';

                echo '<td style="vertical-align:top; width:49%">';
                echo '<img src="' . SITE_WEBROOT . 'img/default.gif" alt="' . htmlspecialchars($location['Location']['name']) . '" width="20" height="20" />';
                echo '<a href="' . SITE_WEBROOT . $data[1]['Location']['url_title'] . '/' . $location['Location']['url_title'] . '" class="countable categories">' . htmlspecialchars($location['Location']['name']) . '</a>';
                echo '</td>';

                if ($i % 2 == 0)
                    echo '</tr>';
                $i++;
            }
        }
        ?>
                    </table>
                </div>
            </div>
    <?php endif; ?>


    <?php
    if (!empty($allCategories)) {
        if ($data[0] == "LOCATION_TYPE") {
            ?>

                <div class="box" >
                    <div class="box-caption-fixed">Категории в <?php echo htmlspecialchars($data[1]["Location"]["name"]); ?></div>
                    <div class="box-content-fixed " >
                        <table border="0" class="categories">
                    <?php
                    if (!empty($allCategories)) {
                        $i = 1;
                        foreach ($allCategories as $category) {
                            if ($i == 1) {
                                echo '<tr>';
                            }
                            echo '<td style="vertical-align: top; width: 49%;">';
                            echo '<img src="' . SITE_WEBROOT . 'img/default.gif" alt="' . htmlspecialchars($category["Category"]["name"]) . '" width="20" height="20" />';
                            //echo '<a href="'.SITE_WEBROOT.$data[1]["Location"]["url_title"].'/'.$category["Category"]["url_title"].'" class="countable categories">'.htmlspecialchars($category["Category"]["name"].' в '.$data[1]["Location"]["name"]).'</a>';
                            echo '<a href="' . SITE_WEBROOT . $locationPath . $category["Category"]["url_title"] . '" class="countable categories">' . htmlspecialchars($category["Category"]["name"]) . '</a>';
                            echo '</td>';
                            if ($i == 2) {
                                echo '</tr>';
                            }

                            if ($i == 2) {
                                $i = 1;
                            } else {
                                $i++;
                            }
                        }
                        if ($i != 1) {
                            echo '</tr>';
                        }
                    }
                    ?>
                        </table>
                    </div>
                    Каталог с фирми в град <?php echo $data[1]["Location"]["name"]; ?>.Бизнес контакти и адреси за населено място <?php echo $data[1]["Location"]["name"]; ?>.Онлайн справочник и фирмен регистър на <?php echo $data[1]["Location"]["name"]; ?> в който ще намерите безплатна полезна информация за фирмите в <?php echo $data[1]["Location"]["name"]; ?>.
                </div>

                <?php
            }
            else if ($data[0] == "CATEGORYLOCATION_TYPE") {
                ?>

                <div class="box" >
                    <div class="box-caption-fixed">Категории в <?php echo htmlspecialchars($data[1]["Category"]["name"]); ?></div>
                    <div class="box-content-fixed " >
                        <table border="0" class="categories">
            <?php
            if (!empty($allCategories)) {
                //$allCategoriesPrefixURL = SITE_WEBROOT.$data[2]["Location"]["url_title"].'/'.$data[1]["CATEGORY_PATH_URL"][(count($data[1]["CATEGORY_PATH_URL"]) - 1)];
                $i = 1;
                foreach ($allCategories as $category) {
                    if ($i == 1) {
                        echo '<tr>';
                    }
                    echo '<td style="vertical-align: top; width: 49%;">';
                    echo '<img src="' . SITE_WEBROOT . 'img/default.gif" alt="' . htmlspecialchars($category["Category"]["name"]) . '" width="20" height="20" />';
                    echo '<a href="/' . $locationPath . $category["Category"]["url_title"] . '" class="countable categories">' . htmlspecialchars($category["Category"]["name"]) . '</a>';
                    echo '</td>';
                    if ($i == 2) {
                        echo '</tr>';
                    }

                    if ($i == 2) {
                        $i = 1;
                    } else {
                        $i++;
                    }
                }
                if ($i != 1) {
                    echo '</tr>';
                }
            }
            ?>
                        </table>
                    </div>
                </div>

            <?php
        }
        else if ($data[0] == "CATEGORY_TYPE") {
            ?>
                <div class="box" >
                    <div class="box-caption-fixed">Категории в <?php echo htmlspecialchars($data[1]["Category"]["name"]); ?></div>
                    <div class="box-content-fixed " >
                        <table border="0" class="categories">
            <?php
            if (!empty($allCategories)) {
                $allCategoriesPrefixURL = SITE_WEBROOT . $data[1]["CATEGORY_PATH_URL"][(count($data[1]["CATEGORY_PATH_URL"]) - 1)];

                $i = 1;
                foreach ($allCategories as $category) {
                    if ($i == 1) {
                        echo '<tr>';
                    }
                    echo '<td style="vertical-align: top; width: 49%;">';
                    echo '<img src="' . SITE_WEBROOT . 'img/default.gif" alt="' . htmlspecialchars($category["Category"]["name"]) . '" width="20" height="20" />';
                    echo '<a href="' . $allCategoriesPrefixURL . '/' . $category["Category"]["url_title"] . '" class="countable categories">' . htmlspecialchars($category["Category"]["name"]) . '</a>';
                    echo '</td>';
                    if ($i == 2) {
                        echo '</tr>';
                    }

                    if ($i == 2) {
                        $i = 1;
                    } else {
                        $i++;
                    }
                }
                if ($i != 1) {
                    echo '</tr>';
                }
            }
            ?>
                        </table>
                    </div>
                </div>
            <?php
        }
    }
    ?>

        <?php
        if (!empty($data[1]["Location"]["body"])) {
            echo '<br />';
            echo $data[1]["Location"]["body"];
            echo '<br />';
        } else if (!empty($data[1]["Category"]["body"])) {
            echo '<br />';
            echo $data[1]["Category"]["body"];
            echo '<br />';
        }

        ?>

        <div class="listings">
            <table cellspacing="0" cellpadding="0" width="100%">
                    <?php
                    $i = 0;
                    $pagenum = $this->Paginator->params();
                    $pagenum = $pagenum['page'];
                    $pagenum = $pagenum - 1;

                    foreach ($listings as $listing) {
                        $k = ($pagenum * 10) + ($i + 1);
                        $class = null;
                        if ($i++ % 2 == 0) {
                            $class = ' class="altrow"';
                        }
                        ?>
                    <tr<?php echo $class; ?>>
                        <td valign="top" style="padding-right: 5px; width: 125px;">
                            <div class="preview" style="margin-bottom: 10px;">
                                <img src="http://open.thumbshots.org/image.pxf?url=<?php echo urlencode($listing["Listing"]["url"]); ?>" alt="<?php echo htmlspecialchars($listing["Listing"]["url"]); ?>" />
                            </div>
                        </td>
                        <td valign="top" style="padding-right: 5px;">
                            <div class="title">
                        <?php echo $k.'.&nbsp;&nbsp;<a href="' . SITE_WEBROOT . $listing["Listing"]["url_title"] . '-l' . $listing["Listing"]["id"] . '.html">' . htmlspecialchars($listing["Listing"]["title"]) . '</a>'; ?>
                            </div>
                            <div class="url"><?php echo htmlspecialchars($listing["Listing"]["url"]); ?></div>
                            <p><?php
                echo $htmlToText->html2text($listing["Listing"]["description"], 160, true);
                echo '</p>';
                  $ts=explode('<br/>',$listing['Listing']['train_stations']);
            $bs=explode('<br/>',$listing['Listing']['bus_stations']);
            $ss=explode('<br/>',$listing['Listing']['subway_stations']);
                        ?>
                                <?if (($ts[0]!=='')){?>
                            <strong>Train Station</strong>
                           <div><? echo $ts[0];}?></div>
                            <?if (($bs[0]!=='')){?>
                            <strong>Bus Station</strong>
                            <div><? echo $bs[0];}?></div>
                            <?if (($ss[0]!=='')){?>
                            <strong>Subway Station</strong>
                            <div><? echo $ss[0];}?></div>
            <?

               // }
            ?>
                            <script></script>

                        </td>
                    </tr>
                <?php } ?>
            </table>
        </div>

        <p>
                <?php
                echo $this->Paginator->counter(array(
                    'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
                ));
                ?>	</p>

        <div class="paging">
    <?php

$pageOptions = $this->Paginator->params();
if( isset($this->params['named']['ind']) && !empty ($this->params['named']['ind']) ) {
    $ind = "/ind:".$this->params['named']['ind'];
} else {
    $ind = "";
}
if( isset($pageOptions['prevPage']) && !empty($pageOptions['prevPage']) ) {
   echo "<a href='http://".$_SERVER['SERVER_NAME'].Router::url('/').$data[1]['Location']['name'].$ind."/page:".$pageOptions['prevPage']."' ><< Previous</a>";
} else {
 echo "<< Previous";
}


for( $i = 1; $i <= $pageOptions['pageCount'] ; $i++ ){

if( $i == $pageOptions['page']) {
    echo $i." | ";
} else {
        echo "<a href='http://".$_SERVER['SERVER_NAME'].Router::url('/').$data[1]['Location']['name'].$ind."/page:".$i."' >".$i." | </a>";
}

}

if( isset($pageOptions['nextPage']) && !empty($pageOptions['nextPage']) ) {
   echo "<a href='http://".$_SERVER['SERVER_NAME'].Router::url('/').$data[1]['Location']['name'].$ind."/page:".$pageOptions['nextPage']."' ><< Next</a>";
} else {
 echo " Next >>";
}


/*echo $this->Paginator->prev('<< ' . __('previous', true), array(), null, array('class' => 'disabled')); ?>
            | 	<?php echo $this->Paginator->numbers(); ?>
            |
    <?php echo $this->Paginator->next(__('next', true) . ' >>', array(), null, array('class' => 'disabled')); */
echo "<br/>";
$a=range("A","Z");
foreach($a as $char) {
	if(in_array($char, $links_p)) {
    	echo "<a href='http://".$_SERVER['SERVER_NAME'].Router::url('/').$data[1]['Location']['name']."/ind:".$char."' >".$char."&nbsp;</a>";
    } else {
    	echo $char;
    }
}

?>
        </div>

                            <?php
                            // static
                            if (($data[0] == "CATEGORYLOCATION_TYPE") || ($data[0] == "CATEGORY_TYPE")) {
                                /* echo '<br />';
                                  // format: array('TITLE', 'URL-TITLE')
                                  $staticLocations = array(
                                  array('London', 'London'),
                                  array('Birmingham', 'Birmingham'),
                                  array('Leeds', 'Leeds'),
                                  array('Sheffield', 'Sheffield'),
                                  array('Bradford', 'Bradford'),
                                  array('Liverpool', 'Liverpool'),
                                  array('Manchester', 'Manchester'),
                                  array('Bristol', 'Bristol'),
                                  array('Wakefield', 'Wakefield'),
                                  array('Coventry', 'Coventry'),
                                  array('Nottingham', 'Nottingham'),
                                  array('Leicester', 'Leicester'),
                                  array('Sunderland', 'Sunderland'),
                                  array('Newcastle', 'Newcastle'),
                                  array('Plymouth', 'Plymouth'),
                                  array('Stoke on Trent', 'Stoke-on-Trent'),
                                  array('Wolverhampton', 'Wolverhampton'),
                                  array('Derby', 'Derby'),
                                  array('Southampton', 'Southampton'),
                                  array('Salford', 'Salford'),
                                  array('Westminster', 'Westminster'),
                                  array('Newport', 'Newport'),
                                  array('Portsmouth', 'Portsmouth'),
                                  array('Brighton', 'Brighton'),
                                  array('York', 'York'),
                                  array('Peterborough', 'Peterborough'),
                                  array('Lancaster', 'Lancaster'),
                                  array('Oxford', 'Oxford'),
                                  array('Preston', 'Preston'),
                                  array('St Albans', 'St-Albans'),
                                  array('Norwich', 'Norwich'),
                                  array('Chester', 'Chester'),
                                  array('Cambridge', 'Cambridge'),
                                  array('Salisbury', 'Salisbury'),
                                  array('Exeter', 'Exeter'),
                                  array('Gloucester', 'Gloucester'),
                                  array('Chichester', 'Chichester'),
                                  array('Worcester', 'Worcester'),
                                  array('Carlisle', 'Carlisle'),
                                  array('Hull', 'Hull'),
                                  array('Winchester', 'Winchester'),
                                  array('Bath', 'Bath'),
                                  array('Durham', 'Durham'),
                                  array('Lincoln', 'Lincoln'),
                                  array('Hereford', 'Hereford'),
                                  array('Canterbury', 'Canterbury'),
                                  array('Lichfield', 'Lichfield'),
                                  array('Ripon', 'Ripon'),
                                  array('Truro', 'Truro'),
                                  array('Ely', 'Ely'),
                                  array('Wells', 'Wells')
                                  );

                                  for($i = 0, $staticLocationsSize = count($staticLocations); $i < $staticLocationsSize; $i++) {
                                  echo '<a href="'.SITE_WEBROOT.$staticLocations[$i][1].'/'.$data[1]["Category"]["url_title"].'/">'.htmlspecialchars($data[1]["Category"]["name"].' в '.$staticLocations[$i][0]).'</a>';
                                  echo ' | ';
                                  }
                                  echo '<a href="'.SITE_WEBROOT.$data[1]["Category"]["url_title"].'/">'.htmlspecialchars('List of '.$data[1]["Category"]["name"]).' в UK</a>';
                                  echo ' | ';
                                  echo '<a href="'.SITE_WEBROOT.'">Moving Directory</a>'; */
                            }
                            ?>

    </div>
        <?php
    } else if (("LISTING_TYPE" == $data[0]) && (!empty($listing))) {
        ?>
    <div class="listings view">
        <h1><?php echo htmlspecialchars($listing['Listing']['title']); ?></h1>
     	<b><?php

     	//echo $listing['Listing']['added_by_user_group'];exit;
	if( $listing['Listing']['added_by_user_group'] != 2 ||  $listing['Listing']['added_by_user_group'] == 1 ||  $listing['Listing']['added_by_user_group'] == 0) {
		if($this->Session->check('Auth.User')){
			$permissions = $listing['Listing']['edit_permission'];
			if(trim($permissions) != ""){
				$permssions = explode(',',$permissions);
				foreach($permssions as $edit){
					if($edit == $this->Session->read('Auth.User.id')){
						$permissions = true;
						break;
					} else {
						$permissions = false;
					}
				}
			} else {
				$permissions = false;
			}

			$claimed = $listing['Listing']['claim_by_users'];
			if(trim($claimed) != ""){
				$claimed= explode(',',$claimed);
				//print_r($claimed);exit;
				foreach($claimed as $edit){
					if($edit == $this->Session->read('Auth.User.id')){
						$claimed = true;
						break;
					} else {
						$claimed = false;
					}
				}
			} else {
				$claimed = false;
			}
			if( $permissions ){
				echo $this->Html->link(__('Edit', true), array('admin'=>false, 'plugin'=>false, 'controller'=>'listings', 'action' => 'claim', $listing['Listing']['id']), array ('style' => 'float: right;margin-top: -25px;'));
			} else if( $claimed ){
				echo "<b style='float: right;margin-top: -25px;' >You have claimed.</b>";
			} else {
				echo $this->Html->link(__('Claim Listing', true), array('admin'=>false, 'plugin'=>false, 'controller'=>'listings', 'action' =>'claim', $listing['Listing']['id'], 'claim'), array ('style' => 'float: right;margin-top: -25px;'));
			}
		}  else {
			echo $this->Html->link(__('Claim Listing', true), array('admin'=>false, 'plugin'=>false, 'controller'=>'listings', 'action' =>'claim', $listing['Listing']['id'], 'claim'), array ('style' => 'float: right;margin-top: -25px;'));
		}
	}
	?>
	</b>
        <div id="listing-rate" style="vertical-align: middle;padding-bottom: 2px;padding-top: 2px;width: 165px">
        <?php
        if ((($i_AVGRating * 2) % 2) == 0) {
            $i_MaxEn = $i_AVGRating;
            $i_MaxDis = 5 - $i_MaxEn;
            $b_Half = false;
        } else {
            $i_MaxEn = $i_AVGRating - 0.5;
            $i_MaxDis = 5 - ($i_MaxEn + 1);
            $b_Half = true;
        }
        ?>
        <?php for ($i = 0; $i < $i_MaxEn; $i++) : ?>
                <img src="<?php echo SITE_WEBROOT; ?>img/stars_enabled.png" width="15"/>
        <?php endfor; ?>
        <?php if ($b_Half): ?>
                <img src="<?php echo SITE_WEBROOT; ?>img/stars_half.png" width="15"/>
        <?php endif; ?>
        <?php for ($i = 0; $i < $i_MaxDis; $i++) : ?>
                <img src="<?php echo SITE_WEBROOT; ?>img/stars_disabled.png" width="15"/>
        <?php endfor; ?>
            <span style="float: right;">&nbsp;&nbsp;<?php echo $i_TotalReview; ?> мнения</span>
            <div style="clear: both;"></div>
        </div>
        <div style="float: left; padding: 10px;">
            <?php if( isset( $listing["Listing"]["photo"] ) && !empty($listing["Listing"]["photo"]) ) { ?>
            <img src="<?php echo  SITE_WEBROOT; ?>/uploads/<?php echo $listing["Listing"]["photo"]; ?>" width="160px" hieght="120px" />
            <?php } else { ?>
            <img src="http://open.thumbshots.org/image.pxf?url=<?php echo urlencode($listing['Listing']['url']); ?>" />
            <?php } ?>
        </div>
        <p>
        <?php echo htmlspecialchars($listing['Listing']['description']); ?>
        </p>
        <div style="clear: both;" />
        <p>
            <strong>Телефон:</strong>
        <?php
        echo htmlspecialchars($listing['Listing']['landline']);
        ?>
        </p>
        <p>
            <strong>GSM:</strong>
    <?php
    echo htmlspecialchars($listing['Listing']['mobile']);
    ?>
        </p>
        <p>
            <strong>Пощенски код:</strong>
            <?php
            echo htmlspecialchars($listing['Listing']['postcode']);
            ?>
        </p>
        <p>
        <p><strong>Адрес:</strong>
            <?php
            echo htmlspecialchars($listing['Listing']['address_1']);
            $ts=($listing['Listing']['train_stations']);
            $bs=($listing['Listing']['bus_stations']);
            $ss=($listing['Listing']['subway_stations']);

            ?></p>
        <? if ($ts!=''){?>
        <strong>Train Station</strong>
        <div><?=$ts?></div>
        <?} if ($bs!=''){?>
        <strong>Bus Station</strong>
        <div><?=$bs?></div>
        <?} if ($ss!=''){?>
        <strong>Subway Station</strong>
        <div><?=$ss?></div>
        <?} ?>
        <? if ($_nearby!=''){?>
        <strong>Places Nearby</strong>
        <div><?=$_nearby?></div>
        <?}?>
    <p>
        <strong></strong>
            <?php
            echo htmlspecialchars($listing['Listing']['address_2']);
            ?>
    </p>
    <br />
    <p>
        <strong>Категория:</strong>
            <?php
            $i = count($listing["CATEGORY_PATH"]) - 1;
            echo '<a href="' . SITE_WEBROOT . $listing["Location"]["url_title"] . '/' . $listing["CATEGORY_PATH_URL"][$i] . '">' . htmlspecialchars($listing["CATEGORY_PATH"][$i]["Category"]["name"]) . ' в ' . htmlspecialchars($listing["Location"]["name"]) . '</a>';
            ?>
    </p>
    <p>
        <strong>Уеб сайт:</strong>
            <?php
            if (__startsWith($listing["Listing"]["url"], "http://") || __startsWith($listing["Listing"]["url"], "https://")) {
                $httpString = '';
            } else {
                $httpString = 'http://';
            }
            echo '<a target="_blank" href="' . $httpString . $listing["Listing"]["url"] . '">' . htmlspecialchars($listing['Listing']['title']) . '</a>';
            ?>
    </p>
    <p>
        <strong>Email:</strong>
            <?php
            echo '<a target="_blank" href="mailto:' . $httpString . $listing["Listing"]["email"] . '">' . htmlspecialchars($listing['Listing']['email']) . '</a>';
            ?>
    </p>
    <p>
        <strong>Opening Hours:</strong>
            <?php
            $dayss = array('Every day', 'Weekdays', 'Weekends', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
            $day = $listing["Listing"]["opening_day"];
            $day = $dayss[$day];

            $hours = array();
				for($i=1; $i<25; $i++){
					$hours[$i] = $i;
				}
            $hr1 = $listing["Listing"]["opening_hour_start"];
            $hr1 = $hours[$hr1];
            $hr2 = $listing["Listing"]["opening_hour_end"];
            $hr2 = $hours[$hr2];
            echo $day."&nbsp;&nbsp;".$hr1."&nbsp;&nbsp;".$hr2;
            ?>
    </p>
    <p>
        <strong>Payment Methods:</strong>
            <?php
            $pay_method = array('Cash,Cheques', 'Direct Debit', 'Credit Cards', 'PayPal', 'Bank Transfers', 'Skrill checkbox');
            $pay = $listing["Listing"]["payment_method"];
            $pay = explode(',', $pay);
            foreach($pay as $val ){
                echo $pay_method[$val].",";
            }
            ?>
    </p>
    <p>
        <strong>Good For:</strong>
            <?php
            $goodFor = array('Children', 'Groups', 'Families', 'Dates', 'Disabled People', 'Business Meetings', 'Birthdays','Parties');
            $forg = $listing["Listing"]["good_for"];
            $forg = explode(',', $forg);
            foreach($forg as $val){
                echo $goodFor[$val].",";
            }
            ?>
    </p>
    <p>
        <strong>Access:</strong>
            <?php
            $access = array('Free Parking', 'Paid Parking', 'Disability Access');
            $acc = $listing["Listing"]["access"];
            $acc = explode(',', $acc);
            foreach($acc as $val){
                echo $access[$val].",";
            }
            
            ?>
    </p>
    <p>
        <strong>Year Established:</strong>
            <?php
            $years = array();
		    for($i = 1900; $i< 2014; $i++){
				$years[$i] =  $i;
			}
            $yr = $listing["Listing"]["year_established"];
            $year = $years[$yr];

            echo $year;
            ?>
    </p>
    <p>
        <strong>Number Of Employee:</strong>
            <?php
            $employee = array('1-5', '5-10', '10-20', '20-50', '50-100', 'over 100');
            $emp = $listing["Listing"]["number_of_employee"];
            $employee = $employee[$emp];

            echo $employee;
            ?>
    </p>
    <p>
        <strong>You Tube Video Url:</strong>
        <?php
			$url = $listing["Listing"]["video"];
			$url_pos = strpos($url, 'v=');
			$url_pos = (int)$url_pos + 2;
			$url_len =  strlen($url);
			$vidID = substr($url, $url_pos, $url_len); 
			if( isset($vidID) && !empty($vidID) ) {
		?>

		<iframe id="ytplayer" type="text/html" width="450" height="260"
		  src="http://www.youtube.com/embed/<?php echo $vidID; ?>"
		  frameborder="0"/>
		<?php } else {?>
				Not Available
		<?php }?>
    </p>
    <br />
    <p>
        <strong>Ключови думи:</strong>
            <?php

            foreach ($listing["ListingTag"] as $listingTag) {
                echo '<a href="' . SITE_WEBROOT . 'tags/' . $listingTag["url_title"] . '">' . htmlspecialchars($listingTag["name"]) . '</a>';
                echo '&nbsp;';
            }
            ?>
    </p>
    <br />
    <ul>
        <li>
        <?php
        $categoryIndex = count($listing["CATEGORY_PATH_URL"]) - 1;
        echo '<a href="' . SITE_WEBROOT . $listing["CATEGORY_PATH_URL"][$categoryIndex] . '">' . htmlspecialchars(' ' . $listing["CATEGORY_PATH"][$categoryIndex]["Category"]["name"] . ' ') . '</a>';
        ?>
        </li>
        <li>
    <?php echo '<a href="' . SITE_WEBROOT . '">' . htmlspecialchars('Бизнес каталог с фирми') . '</a>'; ?>
        </li>
    </ul>
        <?php echo $this->element('review'); ?>
        <?php echo $this->element('listing_review'); ?>
    </div>
    <?php
}
?>

<?php if(isset($yell)) { echo $yell; }?>
